<?php
/**
 * 用户牢骚主页
 *
 *
 */
require_once( './path.php' );

//调用初始化页面
require_once( CLASSMATE_ROOT.'/controller/display_script_init.php' );
require_once( CLASSMATE_ROOT.'/include/function/mongo_connect.function.php' );

//@todo 要改！！！！！！！
if ( !session::get( 'is_online' ) ){
//登录用户才可使用本页面
	 $response_message = array(
			 'type' => 'info' , 
			 'content' => '您还没有登录系统' ,
			 'url_des'=>'马上去登录？' ,
			 'url' => '/classmate/controller/account/login.php' );
			 
	 session::set( 'response_message' , $response_message );

	 header( 'Location: ../response_message.php' );
	 exit();
}

//从数据库中取出用户的相关信息
$db_connect = mongo_connect();

$db_obj_user_profile = new db_obj_user_profile( $db_connect );
$db_obj_user = new db_obj_user( $db_connect );

$email = session::get( 'email' );

$db_obj_user->load( 'email' , $email );
$db_obj_user_profile->load( 'email' , $email );

$user_complaint_process = new user_complaint_process( $db_connect );

//默认情况下显示第一页
if ( $complaints = $user_complaint_process->get_complaint( &$max_page ) ){

	 //如果需要进行分页 
	 if( $max_page > 1 ){
	 
		 session::set( 'next_page' , 2 );
		 $more = true;	 
	 }else{

		 session::set( 'next_page' , 0 );
		 $more = false;
	 }

	 $complaints = iterator_to_array( $complaints );
}

//用户信息
$user_info = array(
	'nick' => $db_obj_user->get( 'nick' ) ,
	'reg_time' => $db_obj_user_profile->get( 'reg_time' ) ,
	'head_url_small' => $db_obj_user_profile->get( 'head_url_small' )
);

$tpl->assign( 'complaints' , $complaints );
$tpl->assign( 'user_info' , $user_info );
$tpl->assign( 'more' , $more );

$tpl->assign( 'title' , '推' );
$tpl->assign( 'active' , 'complaint' );

$tpl->display( 'complaint/index.tpl' );

